#pragma once
#include "CGIResource.h"
namespace Alice
{
    class CGICommandList;
    // Utility flags for modifying render target behavior on a PSO
    enum class EApplyRendertargetOption : int
    {
        DoNothing = 0,			// Just use the PSO from initializer's values, no checking and no modifying (used for PSO precompilation only)
        CheckApply = 1 << 0,	// Verify that the PSO's RT formats match the last Render Target formats set into the CmdList
        ForceApply = CheckApply,// Deprecated. Do not use
    };

    ENUM_CLASS_FLAGS(EApplyRendertargetOption);

    /**
     * PSO Precache request priority
     */
    enum class EPSOPrecachePriority : uint8
    {
        Medium,
        High,
        Highest,
    };

    enum class ERayTracingPipelineCacheFlags : uint8
    {
        // Query the pipeline cache, create pipeline if necessary.
        // Compilation may happen on a task, but RHIThread will block on it before translating the RHICmdList.
        // Therefore the RHIThread may stall when creating large / complex pipelines.
        Default = 0,

        // Query the pipeline cache, create a background task to create the pipeline if necessary.
        // GetAndOrCreateRayTracingPipelineState() may return NULL if pipeline is not ready.
        // Caller must use an alternative fallback PSO to render current frame and may retry next frame.
        // Pipeline creation task will not block RenderThread or RHIThread, allowing hitch-free rendering.
        NonBlocking = 1 << 0,
    };
    ENUM_CLASS_FLAGS(ERayTracingPipelineCacheFlags);

    enum class EPSOPrecacheResult
    {
        Unknown,			//< No known pre cache state
        Active,				//< PSO is currently precaching
        Complete,			//< PSO has been precached successfully
        Missed,				//< PSO precache miss, needs to be compiled at draw time
        TooLate,			//< PSO precache request still compiling when needed
        NotSupported,		//< PSO precache not supported (VertexFactory or MeshPassProcessor doesn't support/implement precaching)
        Untracked,			//< PSO is not tracked at all (Global shader or not coming from MeshDrawCommands)
    };
    
    class FPipelineState
    {
    public:
    };
    class FPipelineStateAsync : public FPipelineState
    {
    private:
    };
    class FGraphicsPipelineState : public FPipelineStateAsync
    {
    public:
        CGIGraphicsPipelineState*mCGIGraphicsPipelineState;
    };
    namespace PipelineStateCache
    {
        FGraphicsPipelineState*	GetAndOrCreateGraphicsPipelineState(CGICommandList& RHICmdList, const FGraphicsPipelineStateInitializer& OriginalInitializer, EApplyRendertargetOption ApplyFlags);
        CGIVertexDeclaration*	GetOrCreateVertexDeclaration(const VertexDeclarationElementList& Elements);
        bool						IsPSOPrecachingEnabled();
    }
    void SetGraphicsPipelineState(CGICommandList& RHICmdList, const FGraphicsPipelineStateInitializer& Initializer, uint32 StencilRef, EApplyRendertargetOption ApplyFlags = EApplyRendertargetOption::CheckApply, bool bApplyAdditionalState = true);
}
#ifdef ALICE_OGL
#include "OpenGL/BufferOGL.h"
#elif ALICE_D3D11
#include "Direct3D/11/BufferD3D11.h"
#elif ALICE_D3D12
#include "Direct3D/12/BufferD3D12.h"
#endif